<?php
require('db.php');

$vak = $_GET['vak'];
$parent = $_GET['parent'];

$result = mysql_query("
SELECT bc.cijfer, c.omschrijving
FROM behaaldecompetenties bc
JOIN (
    SELECT cv.id, cv.competentieID
    FROM competentiespervak cv
    JOIN (
        SELECT id
        FROM competenties
        WHERE parentID='$parent'
        )
    x on(cv.competentieID=x.id)
    WHERE vakID=(
        SELECT id
        FROM vak
        WHERE naam='$vak'
        )
)y
ON (y.id=bc.competentiePerVakID), competenties c
WHERE c.id=y.competentieID") or die (mysql_error());

$data = array();

while ($row = mysql_fetch_object($result)) {
    $data [] = $row;
}

echo json_encode($data);
?>